﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;

namespace Chaunce.FrameWork.NetCore.SysCore.Infrastructure
{
    /// <summary>
    ///定义程序启动初始化配置、服务、模块、组件等注入
    /// </summary>
    public interface IEngine
    {
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="services">服务容器集合</param>
        void Initialize(IServiceCollection services);

        /// <summary>
        /// 新增、配置 服务.注册各种依赖服务、框架
        /// </summary>
        /// <param name="services">Collection of service descriptors</param>
        /// <param name="configuration">Configuration root of the application</param>
        /// <returns>Service provider</returns>
        IServiceProvider ConfigureServices(IServiceCollection services, IConfigurationRoot configuration);

        /// <summary>
        ///配置http 请求管道
        /// </summary>
        /// <param name="application">Builder for configuring an application's request pipeline</param>
        void ConfigureRequestPipeline(IApplicationBuilder application);

        /// <summary>
        /// 泛型 解析依赖 找到实现类型对象
        /// </summary>
        /// <typeparam name="T">服务类型</typeparam>
        /// <returns>实例对象</returns>
        T Resolve<T>() where T : class;

        /// <summary>
        /// 解析类型
        /// </summary>
        /// <param name="type">解析后的类型</param>
        /// <returns>实例对象</returns>
        object Resolve(Type type);

        /// <summary>
        /// 解析依赖(返回所有的实现集合)
        /// </summary>
        /// <typeparam name="T">解析服务类型</typeparam>
        /// <returns>Collection of resolved services</returns>
        IEnumerable<T> ResolveAll<T>();

        /// <summary>
        ///创建 没有被依赖注入的服务 实例
        /// </summary>
        /// <param name="type">Type of service</param>
        /// <returns>Resolved service</returns>
        object ResolveUnregistered(Type type);
    }
}
